package com.td.framework.kqxt.jqgl.action;

import java.util.Date;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.td.framework.common.AbstractAction;
import com.td.framework.kqxt.domain.KqBcsz;
import com.td.framework.kqxt.domain.KqNjgl;
import com.td.framework.kqxt.domain.KqNjgl;
import com.td.framework.webmanager.page.PageService;

/**
 * 年假管理
 * @author Administrator
 */
public class NjglAction extends AbstractAction {
	private KqNjgl kqNjgl;
	private  List<KqNjgl> njglList;
	//=======查询条件====
	private String ryxm;//人员姓名
	
	private Log log = LogFactory.getLog(NjglAction.class);
    
    //=======================================================年假管理START======================================
    
    /**
     * 年假列表集合
     * @return
     */
    public String listNjgl(){
    	String hql ="from KqNjgl t,AppsysRyjbxx t1,AppsysRybmgx t2,AppsysBmxx t3 where t.rybh=t1.rybh and t1.rybh = t2.rybh and t2.bmbh = t3.bmbh";
    	if(ryxm!=null && ryxm.length()>0)
    		hql+=" and t1.xm like '%"+ryxm+"%'";
    	int rows = this.getBaseService().getRowsByListHql(hql);				
		page = PageService.getPage(rows, currentPage, pageSize, pageMethod);
		this.setCurrentPage(page.getCurentPage());		
		this.setPageSize(page.getPageSize());
		njglList =this.getBaseService().getPageList(hql,page.getStartRow(),pageSize);
		return "listNjgl";
    }
    
    /**
     * 打开年假添加页面
     */
    public String createNjglForm(){
    	this.setEditState(1);
    	return "createNjgl";
    }
    
    /**
     * 添加年假信息
     * @return
     */
    public String createNjgl(){
	   boolean flag = false;
		try {
			kqNjgl.setCjr(getUserInfo().getYhm());
			kqNjgl.setCjsj(new Date());
			flag = this.getBaseService().saveEntity(kqNjgl);
		} catch (Exception e) {
			 log.error("增加年假信息失败："+e.getMessage());
			 this.handleMessage("info", "添加失败,联系管理员!");
		}
		if(flag = true){
	    	 this.handleMessage("info", "添加成功，请继续操作!");
	     }
		this.setEditState(1);
	     return "createNjgl";
    }
    
    /**
     *打开修改页面 
     * @return
     */
    public String reworkNjglForm(){
    	this.setEditState(2);
    	kqNjgl = (KqNjgl) this.getBaseService().getEntityById(KqNjgl.class,zids[0]);    
    	return "reworkNjgl";
    }
    
    /**
     * 修改代码表信息
     * @return
     */
    public String reworkNjgl(){
    	this.setEditState(2);
    	 boolean flag = false;
 		try {
 			kqNjgl.setXgr(getUserInfo().getYhm());
			kqNjgl.setXgsj(new Date());
 			flag = this.getBaseService().saveOrUpdate(kqNjgl);
 		} catch (Exception e) {
 			log.error("修改年假设置失败："+e.getMessage());
 			 this.handleMessage("info", "修改失败,请联系管理员!");
 		}
 	     if(flag = true){
 	    	 this.handleMessage("info", "修改成功!");
 	     }
 	     return "reworkNjgl"; 
    }
    
    /**
     * 删除选中年假的信息
     * @return
     */
    public String removeNjgl(){
    	 boolean flag = false;
  	     flag = this.getBaseService().deleteBatch(KqNjgl.class, zids);
  	     return this.listNjgl();
    }
    
    /**
     *打开年假设置展现页面
     * @return
     */
    public String showNjgl(){
    	this.setEditState(2);
    	kqNjgl = (KqNjgl) this.getBaseService().getEntityById(KqNjgl.class,zids[0]);
    	return "showNjgl";
    }
	public KqNjgl getKqNjgl() {
		return kqNjgl;
	}

	public void setKqNjgl(KqNjgl kqNjgl) {
		this.kqNjgl = kqNjgl;
	}

	public List<KqNjgl> getNjglList() {
		return njglList;
	}

	public void setNjglList(List<KqNjgl> njglList) {
		this.njglList = njglList;
	}

	public String getRyxm() {
		return ryxm;
	}

	public void setRyxm(String ryxm) {
		this.ryxm = ryxm;
	}
}
